package com.zl.tby.screen.vo.education;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.zl.tby.core.base.util.ToolsUtil;
import com.zl.tby.model.*;
import com.zl.tby.repository.TbyEducationRoadRepo;
import lombok.Data;

import java.math.BigDecimal;
import java.sql.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 科教宣言-教育资源模块bean
 * @author changpeng
 * @version 1.0
 * @since 2024/8/17 16:25
 */
@Data
public class TbyEducationResourceScreenBean {
    /**选角馆数量*/
    private BigDecimal roomArea;
    private String roomInfo;
    /**解说碑数量*/
    private Long steleCount;
    private String steleInfo;
    /**自然路径长度*/
    private BigDecimal roadLength;
    /**广场面积*/
    private BigDecimal squareArea;
    private String squareInfo;
    /**视图类型的id(物种或宣教馆)*/
    private Long viewBusinessId;
    private String viewBusinessName;
    private String viewBusinessContent;
    private String viewInfo;
    /**资源信息**/
    /**观鸟课程数量*/
    private Integer birdCourse;
    /**植物课程数量*/
    private Integer plantCourse;
    /**自然保护课程数量*/
    private Integer naturalConservationCourse;
    /**鸟类标本*/
    private Integer birdSpecimen;
    /**昆虫标本*/
    private Integer insectSpecimen;
    /**植物标本*/
    private Integer plantSpecimen;
    /**两栖标本*/
    private Integer amphibiansSpecimen;
    /**自然教育人员*/
    private Integer educationPerson;
    /**志愿者*/
    private Integer volunteer;
    /**培训次数*/
    private Long trainCount;

    public TbyEducationResourceScreenBean() {
        this.roadLength = BigDecimal.ZERO;
        this.roomArea = BigDecimal.ZERO;
        this.steleCount = 0L;
        this.squareArea = BigDecimal.ZERO;
    }

    public void fillRoomInformation(List<TbyEducationRoom> roomList) {
        BigDecimal area = BigDecimal.ZERO;
        List<Map<String, Object>> infoList = new ArrayList();
        for (TbyEducationRoom room : roomList) {
            area = ToolsUtil.add(area, room.getArea());
            Map<String, Object> map = new HashMap<>(3);
            map.put("id", room.getId());
            map.put("name", room.getName());
            map.put("lng", room.getLongitude());
            map.put("lat", room.getLatitude());
            infoList.add(map);
        }
        try {
            this.setRoomArea(area);
            this.setRoomInfo(new ObjectMapper().writeValueAsString(infoList));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void setFillSquareArea(List<TbyEducationSquare> list) {
        BigDecimal area = BigDecimal.ZERO;
        List<Map<String, Object>> infoList = new ArrayList();
        for (TbyEducationSquare entity : list) {
            area = ToolsUtil.add(area, entity.getArea());
            Map<String, Object> map = new HashMap<>(3);
            map.put("id", entity.getId());
            map.put("name", entity.getName());
            map.put("lng", entity.getLongitude());
            map.put("lat", entity.getLatitude());
            infoList.add(map);
        }
        try {
            this.setSquareArea(area);
            this.setSquareInfo(new ObjectMapper().writeValueAsString(infoList));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void setFillSteleInformation(List<TbyEducationStele> steleList) {
        long size = 0;
        List<Map<String, Object>> infoList = new ArrayList();
        for (TbyEducationStele stele : steleList) {
            size++;
            Map<String, Object> map = new HashMap<>(3);
            map.put("id", stele.getId());
            map.put("name", stele.getName());
            map.put("lng", stele.getLongitude());
            map.put("lat", stele.getLatitude());
            infoList.add(map);
        }
        try {
            this.setSteleCount(size);
            this.setSteleInfo(new ObjectMapper().writeValueAsString(infoList));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void setFillRoadInformation(List<TbyEducationRoad> roadList) {
        BigDecimal value = BigDecimal.ZERO;
        for (TbyEducationRoad road : roadList) {
            value = ToolsUtil.add(value, road.getLength());
        }
        this.setRoadLength(value);
    }

    public void fillViewInformation(List<TbyEducationView> viewList) {
        List<Map<String, Object>> list = new ArrayList<>();
        for (TbyEducationView view : viewList) {
            Map<String, Object> map = new HashMap<>(2);
            map.put("type", view.getType());
            map.put("fileUrl", view.getFileUrl());
            map.put("fileName", view.getFileName());
            map.put("thumbnailUrl", view.getThumbnailUrl());
            map.put("thumbnailIcon", view.getThumbnailIcon());
            list.add(map);
        }
        try {
            this.setViewInfo(new ObjectMapper().writeValueAsString(list));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void fillResource(TbyEducationResource resource) {
        this.setBirdCourse(resource.getBirdCourse());
        this.setPlantCourse(resource.getPlantCourse());
        this.setNaturalConservationCourse(resource.getNaturalConservationCourse());
        this.setBirdSpecimen(resource.getBirdSpecimen());
        this.setInsectSpecimen(resource.getInsectSpecimen());
        this.setPlantSpecimen(resource.getPlantSpecimen());
        this.setAmphibiansSpecimen(resource.getAmphibiansSpecimen());
        this.setEducationPerson(resource.getEducationPerson());
        this.setVolunteer(resource.getVolunteer());
    }
}
